home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Camelot / Camelot 043 (1989-06)(Swedish User Group of Amiga)(SE)(PD)[WB].zip / Camelot 043 (1989-06)(Swedish User Group of Amiga)(SE)(PD)[WB].adf / shell / shell.doc < prev    next >
Text File  |  1989-01-29  |  39KB  |  1,295 lines

  1.  
  2.         INSTRUCTIONS FOR SHELL Version: 3.02A 20-Dec-88
  3.         ===============================================
  4.  
  5.   Contents
  6.   --------
  7.  
  8.     O.    Changes over old versions
  9.     I.    Description
  10.     II.   Overview of Major features
  11.     III.  Restrictions
  12.     IV.   PIPES
  13.     V.    Command Pre-processor
  14.     VI.   Command Line Editing
  15.     VII.  Function Keys
  16.     VIII. Shell Commands
  17.     IX.   Special Set Variables
  18.     X.    Advanced Topics
  19.     XI.   Example login file
  20.     XII.  Example script file
  21.     XIII. Default values
  22.     XIV.  Why ARP ?
  23.  
  24. O.  Changes over old version
  25.     ------------------------
  26.  
  27. New to 3.02A:
  28.  
  29. - New commands: fornum, forline, strleft, strright, strmid, strlen, exec.
  30. - Improved commands: foreach, pri.
  31. - New system variable _clinumber.
  32. - You can now split long lines in source files (see source for details).
  33. - window -q now lists also position of screens/windows, not only dimension.
  34. - Since strings are handled directly from Shell with new commands,
  35.   rpn is now used only for calculations; string commands are gone.
  36.   However, now RPN is really usable.
  37. - Changed rawgets() to fix some problems with function keys, multi-line
  38.   editing and window resizing; also, fixed bug with ^E.
  39. - cat now warns you if it can't find any file matching your pattern.
  40. - Now uses DOS packets to get ptr to CLI window; this fixes a bug that
  41.   caused problems if Shell was run on unactive windows.
  42. - Fixed minor bugs (htype printed some more ASCII bytes, some commands
  43.   returned random values, history didn't print CR's).
  44. - Heavy mods to this file.
  45.  
  46. New to 3.01A:
  47.  
  48. - Fixed bug with strings: before it printed strings with lenght 1 more
  49.   than specified lenght.
  50. - Made some additions and corrected many errors in Shell.doc (this file).
  51. - Modified handler of external commands to allow things like DATE "?"
  52.   (always use quotes).
  53. - Corrected cat: it didn't work with STDIN before.
  54.  
  55. I.  Description
  56.     -----------
  57.  
  58. This version of Shell is the follow of:
  59.     Shell V2.04 (C)Copyright 1986, Matthew Dillon, All Rights Reserved
  60.     Shell V2.04M-V2.07M by Steve Drew
  61.     Shell V2.08MI and V3.xxA by Carlo Borreo & Cesare Dieni
  62.  
  63. Send suggestions/criticism/anything else to Carlo Borreo or Cesare Dieni at:
  64.  
  65.     BITNET:  PERUGIA@ICNUCEVM.BITNET    
  66.  
  67. or
  68.     Carlo Borreo        Cesare Dieni
  69.     Via G. Berio 34        Via G. Taddei 3
  70.     I-18100 Imperia        I-56100 Pisa
  71.     Italy            Italy
  72.  
  73. For older version: Steve Drew at:
  74.  
  75.         ENET:    CGFSV1::DREW
  76.         ARPA:    drew%cfgsv1.dec.com@decwrl.dec.com
  77.         USENET:  {decvax|decwrl}!cgfsv1.dec.com!drew
  78.  
  79. or
  80.         52 Castledale Cres N.E.
  81.         Calgary, Alberta
  82.         Canada
  83.  
  84. You may distribute this program for non-profit only.
  85.  
  86.  
  87. II. OVERVIEW
  88.     --------
  89.  
  90. Shell provides a convient AmigaDos alternative command interface.
  91. All its commands are internal and thus does not rely on the c:
  92. commands for any functionality.
  93.  
  94. Major features include:
  95.  
  96.     -command line editing
  97.     -shell & Amigados search path support
  98.     -simple history
  99.     -redirection of any command
  100.     -piping
  101.     -aliases
  102.     -variables & variable handling (embedded variables)
  103.     -file name expansion via conventional wild carding ('?', '*' and more)
  104.     -conditionals (if/else ect..)
  105.     -source files  (w/ gotos and labels)
  106.     -many built in commands to speed things up
  107.  
  108.  
  109. III. RESTRICTIONS
  110.      ------------
  111.  
  112.     o AmigaDos execute command will not work. Alternative is to use shell
  113.       own script language (which is more powerful) or to do a 'run execute'.
  114.     o This version runs UNDER WORKBENCH 1.2 or 1.3.
  115.     o VDK handler has a bug with setting file dates so when using the copy
  116.       command and VDK you should use the -d switch otherwise your file date
  117.       in vdk: will be bad. (This is not a bug with shell)
  118.     o If using with conman it may be best to start shell with the -a switch
  119.       (shell -a .login) to turn off shell's command line editing and use
  120.       conmans instead.
  121.  
  122.  
  123. IV. NOTES ON PIPES
  124.     --------------
  125.  
  126.     PIPES have been implimented using temporary RAM: files.  Thus, you
  127.     should be careful when specifying a 'ram:*' expansion as it might
  128.     include the temp. files.  These files are deleted on completion of
  129.     the pipe segment.
  130.  
  131.     The file names used are completely unique, even with multiple shell
  132.     running simultaniously.
  133.  
  134.     My favorite new feature is the fact that you can now redirect to and
  135.     from, and pipe internal commands.  'echo charlie >ram:x', for
  136.     instance.  Another favorite:
  137.  
  138.        echo "echo mem | shell" | shell
  139.  
  140.     To accomplish these new features, I completely re-wrote the command
  141.     parser in execom.c
  142.  
  143.     NO BCPL program should be output-append redirected (>>).
  144.  
  145.  
  146. V.  COMMAND PRE-PROCESSOR
  147.     ---------------------
  148.  
  149.     Preprocessing is done on the command line before it is passed on to
  150.     an internal or external routine:
  151.  
  152.     ^c    where c is a character is converted to that control character.
  153.         Thus, say '^l' for control-l.
  154.  
  155.     $name    where name is a variable name.  Variable names can consist of
  156.         0-9, a-z, A-Z, and underscore (_).  The contents of the
  157.         specified variable is used.  If the variable doesn't exist,
  158.         the specifier is used.  That is, if the variable 'i' contains
  159.         'charlie', then '$i' -> 'charlie'.  If the variable 'i' doesn't
  160.         exist, then '$i'->'$i' .
  161.  
  162.     ;    delimits commands.   echo charlie ; echo ben.
  163.  
  164.     ' '    (a space). Spaces delimit arguments.
  165.  
  166.     "string" a quoted string.  For instance, if you want to echo five spaces
  167.         and an 'a':
  168.  
  169.         echo      a       -> a
  170.         echo "    a"      ->      a
  171.  
  172.     \c    overide the meaning of special characters.  '\^a' is a
  173.         circumflex and an a rather than control-a.  To get a backslash,
  174.         you must say '\\'.
  175.  
  176.         also used to overide alias searching for commands.
  177.  
  178.     >file    specify output redirection.  All output from the command is
  179.         placed in the specified file.
  180.  
  181.     >>file    specify append redirection (Does not work with BCPL programs).
  182.  
  183.     <file    specify input redirection. The command takes input from the
  184.         file rather than the keyboard (note: not all commands require
  185.         input; it makes no sense to say 'echo <charlie' since
  186.         the 'echo' command only outputs its arguments).
  187.  
  188.     |    PIPE specifier.  The output from the command on the left becomes
  189.         the input to the command on the right.  The current SHELL
  190.         implimentation uses temporary files to store the data.
  191.  
  192.     !!    execute the previously executed command.
  193.     !nn    (nn is a number).  Insert the history command numbered n (see
  194.         the HISTORY command)
  195.     !partial search backwards through the history list for a command which
  196.         looks the same as 'partial', and execute it.
  197.  
  198.     #    Enter comment.  The rest of the line is discarded (note: \#
  199.         will, of course, overide the comment character's special
  200.         meaning)
  201.  
  202.  
  203. VI. COMMAND LINE EDITING
  204.     --------------------
  205.  
  206.     o Command line can be upto 255 chars.
  207.     o Inserts and deletes are handled correctly over multiple screen lines.
  208.     o Shell will keep track of the line width should the window get resized.
  209.  
  210.     KEY DEFINITIONS:
  211.         Up Arrow    Recal previous commands
  212.         Down Arrow  Recal commands
  213.         Left Arrow  Move cursor about command line.
  214.         Right Arrow  "     "      "      "      "
  215.         Shift-Up Arrow    Get start of history
  216.         Shift-Down Arrow   "  end   "     "
  217.         Shift-Left Arrow  Moves cursor a bit left
  218.         Shift-Right Arrow   "     "    "  "  right
  219.         ^A        Toggle insert/overtype mode.
  220.         ^D        EOF
  221.         ^E        Put cursor at end of text.
  222.         ^K        Delete to end of line.
  223.         ^R        Retype current line.
  224.         ^U        Erase entire line.
  225.         ^X        Erase entire line.
  226.         ^Z        Put cursor at start of text.
  227.         f1 - f10    Execute command if variable exists.
  228.         F1 - F10    More commands (Shifted f keys).
  229.         Help        Invokes help command
  230.  
  231.  
  232. VII. FUNCTION KEYS
  233.      -------------
  234.  
  235.     Function keys now insert text to the current position on the command
  236.     line. They maybe terminated with a ^M (return). f1 would be non shifted
  237.     where as F1 is shifted.
  238.     Most of functions key have a default definition, but it may be changed.
  239.  
  240.       $ set f1 dir df0:^M
  241.  
  242.     will add the text 'dir df0:<return>' to the current line.
  243.  
  244.       $ set f1 dir
  245.  
  246.     would only add 'dir' you could then enter ' df0:<return>'
  247.  
  248.  
  249. VIII. SHELL COMMANDS
  250.       ---------------
  251.  
  252.    First to start shell from a CLI
  253.  
  254.    shell [-a] [-c command;command]
  255.  
  256.    where:
  257.     -a disables all command line editing features. This is useful for
  258.     when running shell over AUX:, and necessary if you are running
  259.     CONMAN.
  260.  
  261.     -c allows execution of one command line and then exits out of shell.
  262.     This is useful for running a internal shell commands in the
  263.     background or from an external application. eg:
  264.  
  265.         Run shell -c dir df0:; copy -r df0: df1: >nil:; echo "Done"
  266.  
  267.     If you 'Run' shell in the background without the -c switch shell
  268.     will detect this and imediatley exit.
  269.  
  270.    Command execution:
  271.  
  272.    Internal shell commands maybe abreviated.
  273.  
  274.    The first argument is the command-name... here is (in order) how Shell
  275.    tries to execute it:
  276.  
  277.     1) Alias list is searched for an alias exactly matching name.
  278.     2) Internal commands list is scanned for a command even partially
  279.        matching name (so you can, for instance, say resi for resident;
  280.        however, you should specify enough of a command to be unique).
  281.     3) ARP resident list is scanned (you can use Shell's resident
  282.        command to add/remove a file in this list).
  283.     4) At this point, command is supposed to be external (disk), and
  284.        is searched before in current directory, then in Shell's
  285.        path, and finally in AmigaDOS path.
  286.     5) As a last chance, AUTOMATIC SOURCING is tried.
  287.  
  288.    AUTOMATIC SOURCING may be accomplished by naming shell scripts with a
  289.    .sh suffix.  Thus, if you say 'stuff' and the file 'stuff.sh' exists in
  290.    your current or C: directory or anywhere in Shell search path, it will
  291.    be SOURCED with any arguments you have placed in the $_passed variable.
  292.    This is equivalent to typing 'source stuff.sh'
  293.  
  294.    Wild card expansions:
  295.     Most shell commands will accept multiple arguments that can
  296.     be as a result of wild card expansion. Also when the calling
  297.     an external command shell will first expand any wild cards
  298.     to seperate arguments. If you wish to have the external command
  299.     handle it's own wild carding you will need to insert quotes
  300.     around the special wild card characters ? and *.
  301.  
  302.     eg.
  303.         arc a new.arc *.txt    - shell will expand and pass to arc
  304.         arc a new.arc "*.txt"    - let arc expand the wild cards.
  305.  
  306.     Wild card expansions:
  307.  
  308.     ?    match any single character
  309.     *    match any string
  310.     .../*    recursive search down ALL sub directories from current level
  311.     !    Exclude pattern matching specifier
  312.     &    prefixed to patterns, ask confirmation for each file
  313.  
  314.     Examples:
  315.  
  316.     df0:.../*        all files in all directories on df0:
  317.     df0:.../!*.info     full directory tree of df0: but exclude
  318.                 any ugly .info files.
  319.     !*.o !*.c        will result in ALL files matching since what
  320.                 doesn't match the !*.o will match the !*.c
  321.     df1:&*            all files in root of df1:, but ask 
  322.                 confirmation for each
  323.  
  324.     LIST OF COMMANDS:
  325.     -----------------
  326.  
  327.     ABORTLINE
  328.     Usage    : abortline
  329.     Example    : echo a;abort;echo b
  330.     Results    : a
  331.  
  332.     Causes the rest of the line to be aborted. Intended for use in
  333.     conjunction with exception handling.
  334.  
  335.     ADDBUFFERS
  336.     Usage    : addbuffers drive buffers
  337.     Example    : addbuffers df0: 24
  338.  
  339.     Just like AmigaDOS addbuffer command, causes new buffers to be
  340.     allocated for disk I/O. Each buffer costs 512 bytes of CHIP memory.
  341.  
  342.     ALIAS
  343.     Usage    : alias [name [command string] ]
  344.     Example    : alias vt "echo Starting VT100;run sys:tools/vt100"
  345.  
  346.     Sets a name to be a string. You can alias a single name to a set
  347.     of commands if you enclose them in quotes as above. By simply
  348.     typing vt, the command line above would be executed.
  349.  
  350.     Argument Passing to an Alias:
  351.  
  352.     Usage    : alias name "%var [command string]"
  353.     Example    : alias xx "%q echo hi $q, how are ya."
  354.           xx Steve
  355.     Results    : hi Steve, how are ya.
  356.  
  357.     The second form of the alias command allows passing of arguments
  358.     to any position within the command string via use of a variable
  359.     name. To pass arguments to the end of a command string this method
  360.     is actually not necessary.
  361.  
  362.     Typing "alias name" you will get the alias for that name, while with
  363.     "alias" you get a list of all alias.
  364.  
  365.     ASET
  366.     Usage    : aset name value
  367.     Example    : aset INCLUDE include:
  368.  
  369.     Set a variable in a way that is compatible with Aztec SET command;
  370.     this is completely different from Shell variable.
  371.     May even be used to set ARP variables.
  372.  
  373.     ASSIGN
  374.     Usage    : assign [logical [physical] ]
  375.     Example    : assign C: df1:c
  376.  
  377.     Use it like AmigaDOS assign command to set, remove or list
  378.     assignments of logical names to directories.
  379.  
  380.     CAT
  381.     Usage    : cat [-n][file file....]
  382.     Example    : cat foo.txt
  383.  
  384.     Type the specified files onto the screen.  If no file is specified,
  385.     STDIN in used.  CAT is meant to output text files only.
  386.     Specifying -n option you will get numbered lines.
  387.  
  388.     CD
  389.     Usage    : cd [path]
  390.     Example    : cd df0:devs/printers
  391.  
  392.     Change your current working directory.  You may specify '..' to go
  393.     back one directory (this is a CD specific feature, and does not
  394.     work with normal path specifications).
  395.  
  396.     CD without any arguments displays the path of the directory you
  397.     are currently in.
  398.  
  399.     CLOSE
  400.     Usage    : close filenumber
  401.  
  402.     Close the specified file opened by open.
  403.     See open and flist for more info.
  404.  
  405.     COPY
  406.     (CP)
  407.     Usage    : copy [-u][-d] file file
  408.     or    : copy [-u][-d] file1 file2...fileN dir
  409.     or    : copy [-r][-u][-d] dir1 dir2...dirN dir
  410.     options    :
  411.         -r    recursive, copy all subdirectories as well.
  412.         -u    update, if newer version exist on dest, don't copy
  413.         -d    don't set destination file date to that of source.
  414.  
  415.     Example    : copy -r df0: df1:
  416.  
  417.     Copy files or directories. When copying directories, the -r option
  418.     must be specified to copy subdirectories as well.  Otherwise, only
  419.     top level files in the source directory are copied.
  420.  
  421.     All files will be displayed as they are copied and directory's
  422.     displayed as they are created. This output can be suppessed by
  423.     redirecting to nil: eg. copy -r >nil: df0: df1:
  424.  
  425.     Copy will abort after current file on Control-C.
  426.  
  427.     Copy by default sets the date of the destination file to that of
  428.     the source file. To overide this feature use the -d switch.
  429.  
  430.     Another useful option is the -u (update) mode were copy will not
  431.     copy any files which exists already in the destination directory
  432.     if the destination file is newer or equal to the source file.
  433.     This is useful when developing code say in ram: eg. 'copy *.c ram:'
  434.     when done you can copy -u ram: df1: and only those modules you have
  435.     modified will be copied back.
  436.  
  437.     Copy command will now create the destination directory if it does
  438.     not exist when specified as 'copy [-r] dir dir'. If you specify
  439.     copy file file file dir, then 'dir' must already exist.
  440.  
  441.     CP
  442.     Equivalent to copy.
  443.  
  444.     DATE
  445.     Usage    : date [new date and/or time]
  446.     Example    : date Wednesday  # this refers to NEXT wed, of course
  447.  
  448.     Used to read or set system date and/or time. All standard options
  449.     may be used (yesterday, tomorrow, monday, etc.).
  450.     Leading zero's are not necessary.
  451.     Without parameters shows Dddddd DD-MMM-YY HH:MM:SS.
  452.  
  453.     DEC
  454.     Usage    : dec varname [value]
  455.     Example    : dec abc
  456.  
  457.     Decrement the numerical equivalent of the variable with specified
  458.     value (default: 1) and place the ASCII-string result back into
  459.     that variable.
  460.  
  461.     DELETE
  462.     (RM)
  463.     Usage    : delete [-p][-r] file file file...
  464.     Example    : delete foo.txt test.c
  465.  
  466.     Remove (delete) the specified files.  Remove always returns
  467.     errorcode 0.  You can remove empty directories.  The '-r' option
  468.     will remove non-empty directories by recursively removing all sub
  469.     directories.
  470.     You can remove delete-protected files specifying -p option.
  471.     If you specify any wildcard deletes the files will be listed as
  472.     they are deleted. This can be suppressed by redirecting to nil:
  473.  
  474.     DIR
  475.     (LS)
  476.     Usage    : dir [-sdf] [path path ... ]
  477.     Example    : dir df0:
  478.     options    :
  479.         -s  short multi(4) column display.
  480.         -d  list directories only
  481.         -f  list files only
  482.  
  483.     Displays a directory of specified files. Default output shows
  484.     date, protection, block size, byte size and total space used.
  485.     Protections flags include new 1.2/1.3 flags (see under protect).
  486.     Files are alphabetically sorted, without case sensitivity, and
  487.     directories are always in red pen.
  488.  
  489.     DISKCHANGE
  490.     Usage    : diskchange drive
  491.  
  492.     Like AmigaDOS diskchange.
  493.  
  494.     ECHO
  495.     Usage    : echo [-n] string
  496.     Example    : echo hi there
  497.     Results    : hi there
  498.  
  499.     Echo the string given. If -n switch given no newline is
  500.     appended.
  501.  
  502.     ELSE ;
  503.     Usage    : else ; command
  504.     Usage    : if -f foo.c ; else ; echo "Not there" ; endif
  505.  
  506.     Else clause, must follow an IF statement.
  507.  
  508.     ENDIF
  509.     Usage    : endif
  510.  
  511.     The end of an if statement.
  512.  
  513.     Note: if you return from a script file with unterminated IF's
  514.     and the last IF was false, prompt will be changed to an
  515.     underscore ('_') and no commands will be executed until
  516.     'endif' is typed.
  517.  
  518.     EXEC
  519.     Usage    : exec command
  520.     Example    : set util SYS:sytem/utilities
  521.           exec $util/make    # would not work without exec
  522.  
  523.     Execute the command specified; exec command is equivalent to
  524.     command, only you can use variables to specify command name.
  525.  
  526.     FAULT
  527.     Usage    : fault error1 .. errorN
  528.     Example    : fault 205 212
  529.  
  530.     Like AmigaDOS fault, prints specified error messages.
  531.  
  532.     FILENOTE
  533.     Usage: filenote file1 .. filen  note
  534.  
  535.     Set AMIGADOS comment of the specified file. This is not very useful,
  536.     since in current implementation of Shell file comments are not listed
  537.     in directory, but it was so easy to implement...
  538.  
  539.     FLIST
  540.     Usage    : flist
  541.  
  542.     Lists the filenumbers of files opened by open.
  543.     See open and close for more info.
  544.  
  545.     FOREACH
  546.     Usage    : foreach [-v] varname ( strings ) command
  547.     Example    : foreach i ( a b c d ) "echo -n $i;echo \" ha\""
  548.     Result    : a ha
  549.           b ha
  550.           c ha
  551.           d ha
  552.  
  553.     'strings' is broken up into arguments.  Each argument is placed in
  554.     the variable 'varname' in turn and 'command' executed.  To execute
  555.     multiple commands, place them in quotes.
  556.  
  557.     Foreach is especially useful when interpreting passed arguments in
  558.     an alias.
  559.  
  560.     eg.
  561.         foreach i ( *.pic ) viewilbm $i
  562.     assuming a.pic and b.pic in current directory the following commands
  563.     will occur:
  564.         viewilbm a.pic
  565.         viewilbm b.pic
  566.  
  567.     Flag -v causes arguments to be displayed every time command is
  568.     executed.
  569.  
  570.     FOREVER
  571.     Usage    : forever command
  572.     or    : forever "command;command;command..."
  573.  
  574.     The specified commands are executed over and over again forever.
  575.  
  576.     -Execution stops if you hit ^C
  577.     -If the commands return with an error code.
  578.  
  579.    FORLINE
  580.     Usage    : forline var filename command
  581.     or    : forline var filename "command;command..."
  582.     Example    : forline i RAM:temp "echo line $_linenum=$i"
  583.  
  584.     For each ASCII line of file specified commands are executed and
  585.     var points to line content. You can check system variable _linenum
  586.     to find the number of the line currently read.
  587.  
  588.    FORNUM
  589.     Usage    : fornum var n1 n2 command
  590.     or    : fornum var n1 n2 "command;command..."
  591.     Example    : fornum x 1 10 echo $1
  592.  
  593.     Executes command(s) for all numerical values of x between n1 and n2.
  594.  
  595.    GOTO
  596.     Usage    : goto label
  597.     Example    :
  598.           label start
  599.             echo "At start"
  600.             dir ram:
  601.             goto start
  602.  
  603.     Goto the specified label name.  You can only use this command from a
  604.     source file. Labels may now be forward or reverse from current
  605.     position.
  606.  
  607.     HELP
  608.     Usage    : help
  609.     Example    : help
  610.  
  611.     Simply displays all the available commands.  The commands are
  612.     displayed in search-order.  That is, if you give a partial name
  613.     the first command that matches that name in this list is the one
  614.     executed.  Generally, you should specify enough of a command so that
  615.     it is completely unique.
  616.  
  617.     HISTORY
  618.     Usage    : history [partial_string]
  619.     Example    : history
  620.  
  621.     Displays the enumerated history list.  The size of the list is
  622.     controlled by the _history variable.  If you specify a partial-
  623.     string, only those entries matching that string are displayed.
  624.  
  625.     HOWMANY
  626.     Usage    : howmany
  627.  
  628.     This command tells you how many instances of Shell are running
  629.     in your system.
  630.  
  631.     HTYPE
  632.     Usage    : htype file1 .. filen
  633.  
  634.     Displays the specified files in hex and ASCII, just like the system
  635.     command Type file opt h. Especially suitable for binary files.
  636.  
  637.     IF
  638.     Usage    : if [-n] argument conditional argument ;
  639.     or    : if [-n] argument
  640.     or    : if [-n] -f file
  641.     or    : if [-n] -d file/dir
  642.     or    : if [-n] -m
  643.     or    : if [-n] -t file file1 .. fileN
  644.     or    : if [-n] -r rpnexpression
  645.  
  646.     If a single argument is something to another argument.  Conditional
  647.     clauses allowed:
  648.  
  649.     <, >, =, and combinations (wire or).  Thus <> is not-equal, >=
  650.     larger or equal, etc...
  651.  
  652.     If arguments are not numeric, they are compared as strings.
  653.  
  654.     Usually the argument is either a constant or a variable ($varname).
  655.  
  656.     The second form if IF is conditional on the existance of the argument.
  657.     If the argument is a "" string, then false , else TRUE.
  658.  
  659.     The third form of IF used by -f switch checks for existance of
  660.     the specified file.
  661.  
  662.     Switch -d tests the type of the object specified: if it is a
  663.     directory, then TRUE; if it is a file (or it doesn't exist)
  664.     then FALSE.
  665.  
  666.     Switch -m is used to test if FAST memory is present, i.e. wheter
  667.     more than 512K RAM are available.
  668.     Example (to be included in a login.sh file):
  669.     if -m; resident -a as ln cc; endif
  670.  
  671.     Using -t form compares the date and time of the first file with
  672.     all the others; if the first is younger than ALL the others, then
  673.     FALSE, else TRUE. If a file doesn't exists, it is considered as
  674.     being older.
  675.     This feature is especially useful for building makefiles without
  676.     using any MAKE utility.
  677.     Example:
  678.     if -t test.o test.asm test.i ; asm -o test.o test.asm ; endif
  679.  
  680.     Option -r evaluates a given RPN expression (see under RPN for more
  681.     info): if value on top of stack is 0, then FALSE, else TRUE.
  682.  
  683.     Switch -n (NOT) reverses the result.
  684.  
  685.     When using 'IF' command interactively if you are entering commands
  686.     following an 'IF' that was false, the prompt will be set to a
  687.     underscore '_ ' to indicate all commands will be ignored until
  688.     an 'ELSE' or 'ENDIF' command is seen.
  689.  
  690.     INC
  691.     Usage    : inc varname [value]
  692.     Example    : inc abc 5
  693.  
  694.     Increment the numerical equivalent of the variable with specified
  695.     value (default: 1) and place the ascii-string result back into
  696.     that variable.
  697.  
  698.     INFO
  699.     Usage    : info
  700.  
  701.     Display Device statistics for all the disk-type devices in system
  702.     (DFk:, HDk, JHk:, RAM:, RDk: ...), just like the system command
  703.     info. Gives block used/free, % used, errs, status and volume name.
  704.  
  705.     INPUT
  706.     Usage    : input var var ... var
  707.     Example    : input abc
  708.  
  709.     Input from STDIN (or a redirection, or a pipe) to a variable.  The
  710.     next input line is placed in the variable.
  711.  
  712.     JOIN
  713.     Usage    : join [-r] file1..fileN destfile
  714.     Example    : join part1 part2 part3 total
  715.  
  716.     Joins the specified files to get destfile. If destfile already
  717.     exists, an error message is generated and operation is aborted,
  718.     unless you specify -r (replace) option.
  719.  
  720.     LABEL
  721.     Usage    : label name
  722.  
  723.     Create a program label right here. Used in source files, can then
  724.     GOTO a label.
  725.  
  726.     LS
  727.     Equivalent to dir.
  728.  
  729.     MD
  730.     Equivalent to mkdir.
  731.  
  732.     MEM
  733.     Usage    : mem
  734.  
  735.     Display current memory statistics for CHIP memory and
  736.     FAST memory (if any installed).
  737.  
  738.     MKDIR
  739.     (MD)
  740.     Usage    : mkdir name name name...
  741.     Example    : mkdir df0:stuff
  742.  
  743.     Create the specified directories.
  744.  
  745.     MV
  746.     Equivalent to rename.
  747.  
  748.     OPEN
  749.     Usage    : open filename filemode filenumber
  750.     Example    : open RAM:data w 1
  751.  
  752.     This allows you to open a file, redirect to it as many commands
  753.     as you like, then close it.
  754.     Filename is any valid AmigaDOS filename, filemode is either r
  755.     for read or w for write, filenumber is a number between 1 and 10.
  756.     To redirect a program to or from an open file, use as your redir
  757.     filename a dot followed by the filenumber.
  758.     Here is a complete example:
  759.  
  760.         open RAM:data w 1
  761.         echo -n 2+2= >.1
  762.         rpn 2 2 + . CR >.1
  763.         close 1
  764.         type RAM:data    # will display 2+2=4
  765.     See also close, flist.
  766.  
  767.     PATH
  768.     Usage    : path
  769.  
  770.     Used to list AmigaDOS path. In current version can't be used to
  771.     set it.
  772.  
  773.     PRI
  774.     Usage    : pri clinumber pri
  775.     Example    : pri 3 5    # set priority of cli #3 to 5
  776.  
  777.     Change the priority of the specified task (use PS command to
  778.     determine clinumber). If you specify 0 as clinumber you can
  779.     change priority of "this" task (the one executing shell).
  780.  
  781.     PROTECT
  782.     Usage    : protect file1 ... filen [flags]
  783.     Example    : protect myfile rwe
  784.  
  785.     Set AMIGADOS file protection flags for the file specified. Valid
  786.     flags are h, s, p, a, r, w, e, d.
  787.     If you don't specify the flags, all flags are cleared.
  788.     Bit 'a' is new to WorkBench 1.2, while 'h', 's', 'p' are new to 1.3.
  789.  
  790.     PS
  791.     Usage    : ps
  792.  
  793.     Gives status of DOS processes.  eg:
  794.  
  795.     Proc Command Name    CLI Type    Pri.  Address  Directory
  796.      1   SHELL        Initial CLI   0      97b0  Stuff:shell
  797.      2   sys:c/clockmem    Background  -10    2101a8  Workdisk:
  798.      3   c:emacs        Background    0    212f58  Stuff:shell
  799.      4   sys:c/VT100    Background    0    227328  Workdisk:
  800.  
  801.     Address is the addres of the task, directory is the process
  802.     currently CD'd directory.
  803.  
  804.     PWD
  805.     Usage    : pwd
  806.  
  807.     Rebuild _cwd by backtracing from your current directory.
  808.  
  809.     QUIT
  810.     Usage    : quit
  811.  
  812.     Quit out of Shell back to CLI.
  813.  
  814.     RBACK
  815.     Usage    : rback command
  816.  
  817.     Start a new process executing the specified command, but can't do
  818.     input/output. Equivalent to 'run command >NIL: <NIL:'.
  819.     This command is not fully reliable: use at your own risk.
  820.  
  821.     RENAME
  822.     (MV)
  823.     Usage    : rename from to
  824.     or    : rename from from from ... from todir
  825.  
  826.     Allows you to rename a file or move it around within a disk.
  827.     Allows you to move 1 or more files into a single directory.
  828.  
  829.     RESIDENT
  830.     Usage    : resident [-a][-r] [files]
  831.  
  832.     This is ARP resident. Commands are searched by Shell in resident
  833.     list BEFORE of searching on any external device.
  834.     Option -a loads RESIDENT programs, -r removes them.
  835.     Resident with no args lists resident programs.
  836.     Not all programs can run as resident, see ARP docs for more info.
  837.  
  838.     RETURN
  839.     Usage    : return [n]
  840.     Example    : return 10
  841.  
  842.     Exit from a script file, or quit from shell with optional
  843.     exit code.
  844.  
  845.     RM
  846.     Equivalent to delete.
  847.  
  848.     RPN
  849.     Usage    : rpn expression
  850.     Example    : rpn 3 7 *    # Prints the value 21
  851.  
  852.     Evaluate an RPN expression, using 32-bit values. In older versions
  853.     of Shell RPN contained string functions too, but now that strings
  854.     are handled by specifical commands, these are no more needed.
  855.     At end of evaluation, RPN prints values on stack, so you can
  856.     say for instance "rpn $x 2 * | input x" to double the value of
  857.     variable x.
  858.     Functions implemented are:
  859.  
  860.         + - * /    Obvious meaning; / means integer division, of course
  861.         %        Module operator e.g. "rpn 7 3 %" answers 1
  862.         & | ~    Bitwise and, or, not operators
  863.         > < ==    Tests for greater-than, lower-than, equal. To get
  864.             a test for >= (or <=), you can use < ! (or > !)
  865.         !        Logical not operator
  866.         DUP        Duplicate value on top of stack
  867.         DROP    Drop value on top of stack
  868.         SWAP    Swap two values on top of stack
  869.  
  870.     RUN
  871.     Usage    : run prgm args
  872.     Example    : run emacs test.c
  873.  
  874.     Start a new process executing the specified command.
  875.     In current implementation run command can't be redirected.
  876.     This command is not fully reliable: use at your own risk.
  877.     See also rback.
  878.  
  879.     SEARCH
  880.     Usage    : search [-w][-c][-n][-r][-e][-q] filelist string
  881.  
  882.     Search specified files for a string. Only lines containing the
  883.     specified strings are displayed.
  884.  
  885.     If you specify any directory in filelist, and use the -r (recurse)
  886.     switch, all files in directory are recursively searched.
  887.  
  888.     Lines are numbered for default; use -n (number) switch to turn off
  889.     line numbering.
  890.  
  891.     Search is normally not case sensitive; use -c (case) flag to turn ON
  892.     case sensitivity.
  893.  
  894.     By specifying -e (exclude) switch, only lines NOT containing the
  895.     specified string are listed.
  896.  
  897.     Using -w (wild) flag, only the lines matching with the string are
  898.     listed.
  899.     Notes to wild card matching;
  900.     - Uses Shell standard matching.
  901.     - Wild cards allowed are *, ?, !.
  902.     - Matching is not case sensitive (even if you use -c flag).
  903.     - The WHOLE line must match the string, not only a substring.
  904.     - String MUST be enclosed in quotes to avoid wildcard expansion
  905.  
  906.     Flag -q (quiet) suppresses printing of file names.
  907.  
  908.     Examples:
  909.         search -c -r df0:include ACCESS
  910.     Find all occurrencies of ACCESS (in uppercase) in all files
  911.     contained in include directory.
  912.         search -w shell.h "#define*"
  913.     Lists only lines of file beginning with (not simply containing)
  914.     #define.
  915.  
  916.     SET
  917.     Usage    : set [name] [string]
  918.     Example    : set abc hello
  919.  
  920.     Set with no args lists all current variable settings.
  921.     Set with one arg lists the setting for that particular variable.
  922.     Specifying name and string, stores the string into variable name.
  923.  
  924.     Also See the section on special _variables.
  925.  
  926.  
  927.     SLEEP
  928.     Usage    : sleep timeout
  929.     Example    : sleep 10
  930.  
  931.     Sleep for 'timeout' seconds, or until ^C typed.
  932.  
  933.     STACK
  934.     Usage    : stack [number]
  935.     Example    : stack 8000
  936.  
  937.     Changes the default stack for this CLI. Without arguments, prints
  938.     it.
  939.  
  940.     STRHEAD
  941.     Usage    : strhead varname breakchar string
  942.     Example    : strhead j . foobar.bas
  943.           echo $j
  944.     Result    : foobar
  945.  
  946.     Remove everything after and including the breakchar in 'string' and
  947.     place in variable 'varname'.
  948.  
  949.     STRINGS
  950.     Usage    : strings file1..fileN minlenght
  951.     Example    : strings c:dir c:list shell 7
  952.  
  953.     Prints strings contained in specified files (usually binary)
  954.     with lenght >= minlenght.
  955.  
  956.     STRLEFT
  957.     Usage    : strleft varname string n
  958.     Example    : strleft x LongString 5    # Will set x to "LongS"
  959.  
  960.     Place leftmost n chars of string in variable varname.
  961.  
  962.     STRLEN
  963.     Usage    : strlen varname string
  964.     Example    : strlen x Hello    # Will set x to "5"
  965.  
  966.     Puts len of string in variable varname.
  967.  
  968.     STRMID
  969.     Usage    : strmid varname string n1 [n2]
  970.     Example    : strmid x LongString 5 3    # Will set x to "Str"
  971.  
  972.     Places n2 chars from string, starting at n1, in variable varname.
  973.     By omitting n2, you get all chars from n1 to end of string.
  974.  
  975.     STRRIGHT
  976.     Usage    : strright varname string n
  977.     Example    : strright x LongString 5    # Will set x to "tring"
  978.  
  979.     Place rightmost n chars of string in variable varname.
  980.  
  981.     STRTAIL
  982.     Usage    : strtail varname breakchar string
  983.     Example    : strtail j . foobar.bas ; echo $j
  984.     Result    : bas
  985.  
  986.     Remove everything before and including the breakchar in 'string' and
  987.     place in variable 'varname'.
  988.  
  989.     SOURCE
  990.     Usage    : source file [arguments]
  991.     Example    : source mymake.sh all
  992.     Result    : source file 'mymake.sh' called with var _passed = 'all'
  993.  
  994.     Execute commands from a file.  You can create SHELL programs in
  995.     a file and then execute them with this command.  Source'd files
  996.     have the added advantage that you can have loops in your command
  997.     files (see GOTO and LABEL).  You can pass SOURCE files arguments
  998.     by specifying arguments after the file name.  Arguments are passed
  999.     via the _passed variable (as a single string).
  1000.  
  1001.     Long lines may be split by appending a backslash (\) at end of
  1002.     first half. However, even joined lines cannot be longer than
  1003.     ~255 chars. See example of source files.
  1004.  
  1005.     Automatic 'sourcing' is accomplished by placing a .sh extension on
  1006.     the file and executing it as you would a C program:
  1007.  
  1008.     --------- file hello.sh ---------
  1009.     foreach i ( $_passed ) "echo yo $i"
  1010.     ---------------------------------
  1011.  
  1012.     $ hello a b c
  1013.     yo a
  1014.     yo b
  1015.     yo c
  1016.  
  1017.     TYPE
  1018.     Equivalent to CAT.
  1019.  
  1020.     TOUCH
  1021.     Usage    : touch file1 .. fileN
  1022.  
  1023.     Sets DateStamp on the specified files to the current date and time.
  1024.  
  1025.     UNALIAS
  1026.     Usage    : unalias name .. name
  1027.     Example    : unalias vt
  1028.  
  1029.     Delete aliases..
  1030.  
  1031.     UNSET
  1032.     Usage    : unset name .. name
  1033.     Example    : unset abc
  1034.  
  1035.     Unset one or more variables.  Deletes them entirely.
  1036.  
  1037.     VER
  1038.     Usage    : ver
  1039.  
  1040.     Show current version name, & authors.
  1041.  
  1042.     WINDOW
  1043.     Usage    : window [-q][-f][-b][-l][-s] [dimensions]
  1044.     Options    :
  1045.         -f    (front) Window to front
  1046.         -b    (back)  Window to back
  1047.         -l    (large) Window to maximum size
  1048.         -s    (small) Window to minimum size
  1049.         -a    (activate)
  1050.         -q    (query) Lists screens and windows open
  1051.  
  1052.     Various operations on CLI window. If dimensions are specified,
  1053.     they must be in the form x y width height, with values separated
  1054.     by spaces.
  1055.     The command "window -l" may be very useful on PAL machines to
  1056.     get a full PAL window from your login sequence, or if you use
  1057.     overscan WorkBench.
  1058.     Option -q gives, for each Screen and Window currently open,
  1059.     title, left edge, top edge, width, height.
  1060.  
  1061.  
  1062. IX. SPECIAL SET VARIABLES
  1063.     ---------------------
  1064.  
  1065.     _prompt
  1066.     This variable is set to the string you wish printed as your
  1067.     prompt. This can contain escape sequences if you wish, or
  1068.     you can include a %p in path definition to get CD in your
  1069.     prompt.
  1070.     Default prompt shows path specification in red pen, followed by
  1071.     a greater (>) sign and a space.
  1072.     The if command will set the prompt to a '_ ' if commands are
  1073.     disabled while waiting for a 'endif' or 'else' command. Interactive
  1074.     mode only.
  1075.  
  1076.     _history
  1077.     This variable is set to a numerical value, and specifies how far
  1078.     back your history should extend.
  1079.  
  1080.     _debug
  1081.     Debug mode... use it if you dare.  must be set to some value
  1082.  
  1083.     _verbose
  1084.     Verbose mode (for source files).  display commands as they are
  1085.     executed.
  1086.  
  1087.     _maxerr
  1088.     The worst (highest) return value to date.  To use this, you usually
  1089.     set it to '0', then do some set of commands, then check it.
  1090.  
  1091.     _lasterr
  1092.     Return code of last command executed.  This includes internal
  1093.     commands as well as external comands, so to use this variables
  1094.     you must check it IMMEDIATELY after the command in question.
  1095.  
  1096.     _cwd
  1097.     Holds a string representing the current directory we are in from
  1098.     root.  The SHELL can get confused as to its current directory if
  1099.     some external program changes the directory.  Use PWD to rebuild
  1100.     the _cwd variable in these cases.
  1101.  
  1102.     _passed
  1103.     This variable contains the passed arguments when you SOURCE a file
  1104.     or execute a .sh file.  For instance:
  1105.  
  1106.     test a b c d
  1107.  
  1108.     -------- file test.sh ----------
  1109.     echo $_passed
  1110.     foreach i ( $_passed ) "echo YO $i"
  1111.     --------------------------------
  1112.  
  1113.     _path
  1114.     This variable contains the search path when the shell is looking
  1115.     for external commands.  The format is:  DIR,DIR,DIR  Each DIR must
  1116.     have a trailing ':' or '/'.  The current directory is always
  1117.     searched first.  The entire path will be searched first for the
  1118.     <command>, then for <command>.sh (automatic shell script sourcing).
  1119.  
  1120.     The default _path is set to
  1121.         ram:,ram:c/,df0:c/,df1:c/,df0:,df1:,sys:system/
  1122.  
  1123.     _insert
  1124.     Sets the default for insert/overtype mode for command line
  1125.     editing. ^A toggles between, but after <RET> the default is
  1126.     set back as indicated by this variable. By default _insert is 1
  1127.     indicating insert mode on setting to zero will make overtype
  1128.     the default.
  1129.  
  1130.     _titlebar
  1131.     Used to set window's title bar.
  1132.  
  1133.     _clinumber
  1134.     Contains the number (1-20) of current CLI.
  1135.  
  1136. X.  ADVANCED TOPICS
  1137.     ---------------
  1138.  
  1139.     EXCEPTION_PROCESSING:
  1140.  
  1141.     if no _except variable exists, any command which fails causes the
  1142.     rest of the line to abort as if an ABORTLINE had been executed.  If
  1143.     the _except variable exists, it is of the form:
  1144.  
  1145.     "nnn;commands..."
  1146.  
  1147.     where nnn is some value representing the minimum return code required
  1148.     to cause an error.  Whenever a command returns a code which is
  1149.     larger or equal to nnn, the commands in _except are executed before
  1150.     anything.  WHEN _except EXISTS, THE COMMAND LINE DOES NOT ABORT
  1151.     AUTOMATICALLY.  Thus, if you want the current line being executed
  1152.     to be aborted, the last command in _except should be an "abortline".
  1153.  
  1154.     exception handling is disabled while in the exception handling routine
  1155.     (thus you can't get into any infinite loops this way).
  1156.  
  1157.     Thus if _except = ";", return codes are completely ignored.
  1158.  
  1159.     example:
  1160.  
  1161.     set _except "20;abortline"
  1162.  
  1163. XI. EXAMPLE LOGIN FILE
  1164.     ------------------
  1165.  
  1166. If from a CLI or the startup-script you say 'SHELL filename', that file is
  1167. sourced first.
  1168. If you are a CLI user, your startup-sequence may be as simple as:
  1169.  
  1170.     C:Shell S:login.sh
  1171.  
  1172. Here is, my startup code:
  1173.  
  1174. ### Example S:login.sh ###
  1175.  
  1176. window -l    # if you are on a PAL machine, or use overscan
  1177.  
  1178. set _prompt ^[[33m[$_clinumber].%p>" "
  1179.  
  1180. set F5 "cdir WORK:"^M
  1181. set f9 "ed s:login.sh"^M
  1182. set F9 "ed df0:s/startup-sequence"^M
  1183. alias toram  "%q foreach i ( $q ) \"cp -r $i: ram:$i >NIL:;\
  1184.     assign $i: ram:$i\""
  1185. alias ramop  "md RAM:op; assign OP: ram:op"
  1186. alias noop   "assign OP: ; rm -r ram:op"
  1187. alias newop  "rm -r OP:*"
  1188. alias dc     "dfc df0: to df1:"
  1189. alias go     "%q assign WORK: Boot:$q; cd WORK:; source startme.sh"
  1190. alias get    "%q cp $q RAM: >NIL:"
  1191.  
  1192. assign LC:    Stuff:c
  1193. assign INCLUDE:    Stuff:include
  1194. assign LIB:    Boot:lib
  1195. assign QUAD:    RAM:
  1196.  
  1197. rback C:FaccII; sleep 1
  1198.     # after spawning a process, it is always better to allow it
  1199.     # to load the command, to avoid excessive drive head movement
  1200.  
  1201. C:REZ Blink CC LC1 LC2 >NIL:
  1202.  
  1203. C:PopCli 300 C:Newcli
  1204. C:FF -1 Siesta.font >NIL:
  1205. C:Patch_1 >NIL:
  1206. stack 8000    # lc1 and lc2 need this
  1207.  
  1208. source S:setdate.sh    # this is listed in next chapter
  1209.  
  1210. ### End of example login.sh ###
  1211.  
  1212.  
  1213. XII.  Example Source file
  1214.       -------------------
  1215.  
  1216. The following is an example source file to set date and time; it may be
  1217. used at startup if you don't have an internal clock.
  1218.  
  1219. ### setdate.sh ###
  1220.  
  1221. open CON:200/100/440/80/SetDate write 1
  1222. echo >.1 -n "Current date is "
  1223. date >.1
  1224. echo >.1 -n "Please enter date: "
  1225. input <.1 d
  1226. close 1
  1227. strlen len $d
  1228. if -r $len 1 > ; date $d ; endif
  1229. echo -n "New date: " ; date
  1230.  
  1231. ### End of setdate.sh ###
  1232.  
  1233. Next comes a makefile that needs no Make program: may be executed from
  1234. Shell directely!!!
  1235.  
  1236. ### make.sh ###
  1237.  
  1238. if -t Shell.syms Shell.h; cc +HShell.syms Shell.h; rm shell.o; endif
  1239. if -t RAM:Shell.syms Shell.syms; cp -d Shell.syms RAM:; endif
  1240.  
  1241. foreach i ( main comm1 comm2 comm3 execom globals rawconsole run set \
  1242.  sub ) "if -t $i.o $i.c; echo Compile $i...;cc +IRAM:shell.syms $i.c; endif"
  1243.  
  1244. if -t Shell run.o main.o comm1.o comm2.o comm3.o execom.o \
  1245. set.o sub.o globals.o rawconsole.o
  1246.             ln  +q -m -o Shell run.o main.o comm1.o comm2.o comm3.o\
  1247.         execom.o set.o sub.o globals.o rawconsole.o -la -lc
  1248. endif
  1249.  
  1250. ### End of make.sh ###
  1251.  
  1252.  
  1253. XIII.  Default Values
  1254.        --------------
  1255.  
  1256. To make things easier, some aliases are predefined whenever you start a
  1257. new Shell. These are:
  1258.  
  1259.     - cls
  1260.     Simply clear the screen.
  1261.  
  1262.     - cdir
  1263.     Use "cdir directory" to clear the screen, set CD to directory,
  1264.     and list it.
  1265.  
  1266.     - kr
  1267.     Deletes everything on RAM:. If you think this is dangerous,
  1268.     you can remove this alias.
  1269.  
  1270.     - exit
  1271.     Leave Shell and exit CLI.
  1272.  
  1273. Moreover, many variables have default values, and many function keys are
  1274. predefined. You can use set command to determine all of these.
  1275.  
  1276. XIV.  Why ARP ?
  1277.       ---------
  1278.  
  1279. For those of you curious enough, the A in "3.xxA" means ARP. The most
  1280. recent versions of Shell use ARP.library. This has been very useful in:
  1281.  
  1282.  - Implementing commands like ASET, ASSIGN, INFO, RESIDENT, RBACK, RUN.
  1283.  - Keeping executable code small.
  1284.  
  1285. ARP.library is really public domain, so one can include it in any package,
  1286. both commercial or public domain, like I am doing with Shell.
  1287. The ARP team is trying to wipe out the BCPL from AMIGA. This is a very
  1288. good idea, I think. And there is a lot of people hoping that Commodore
  1289. will put ARP.library in ROM, before or after. This would  make the AMIGA
  1290. a very mory friendly computer to use and program.
  1291. I encourage programmers to get ARP development package: you can find it
  1292. on many BBS, and is really public domain. Users can look for a replacement
  1293. of C: commands from ARP (but, of course, if you use this Shell you won't
  1294. need them anymore, except for ARUN).
  1295.